﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using umbraco;
using System.Data;
using System.Data.SqlClient;

namespace TheOutfield.UmbExt.PrivateMessaging.UserControls
{
    public partial class PrivateMessagingCoreInstaller : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InstallDatabase();
        }

        private void InstallDatabase()
        {
            StreamReader reader = new StreamReader(base.Server.MapPath("/umbraco/theoutfield/privatemessaging/install/install.1.0.0.sql.txt"));
            string sqlStatement = reader.ReadToEnd();
            reader.Close();

            using (SqlConnection connection = new SqlConnection(GlobalSettings.DbDSN))
            {
                SqlCommand command = new SqlCommand(sqlStatement, connection);
                command.Connection.Open();
                command.ExecuteNonQuery();
            }
        }
    }
}